/**
 * 
 */
package edu.ou.cs.youming.jaxb.types.attributes;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import edu.ou.cs.youming.jaxb.types.Attribute;
import edu.ou.cs.youming.jaxb.types.Feature;

/**
 * Simple attribute that checks if a feature contains a word or not
 * 
 * @author Youming Lin
 * 
 */
@XmlRootElement(name = "WPAttribute")
public final class WPAttribute implements Attribute {
	@XmlElement(name = "word")
	final String word;

	protected WPAttribute() {
		word = null;
	}

	public WPAttribute(final String word) {
		this.word = word;
	}

	@Override
	public int featureIndex(final Feature f) {
		if (f.frequencies.containsKey(word) && f.frequencies.get(word) > 0) {
			return 0;
		}
		else {
			return 1;
		}
	}

	@Override
	public int numberOfIntervals() {
		return 2;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "WPAttribute [word=" + word + "]";
	}
}